#include "BlockQueue.hpp"
#include <pthread.h>
#include <unistd.h>

using namespace BlockQueueModule;

void* consumer(void* args) {
    BlockQueue<int>* bq = static_cast<BlockQueue<int>*>(args);
    while (true) {
        int data;
        bq->DQueue(&data);
        printf("consume data: %d\n", data);
        sleep(1);
    }
    return nullptr;
}

void* producer(void* args) {
    BlockQueue<int>* bq = static_cast<BlockQueue<int>*>(args);
    int data = 5;
    while (true) {
        bq->EQueue(data);
        printf("produce data: %d\n", data);
        data++;
        sleep(1);
    }
    return nullptr;
}

int main() {
    BlockQueue<int> bq(10);
    pthread_t c1,c2,p1,p2;
    pthread_create(&c1, nullptr, consumer, &bq);
    pthread_create(&c2, nullptr, consumer, &bq);
    pthread_create(&p1, nullptr, producer, &bq);
    pthread_create(&p2, nullptr, producer, &bq);

    pthread_join(c1, nullptr);
    pthread_join(c2, nullptr);
    pthread_join(p1, nullptr);
    pthread_join(p2, nullptr);

    return 0;
}